package com.isunland.managesystem.adapter;

import android.content.Context;
import android.graphics.Color;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.isunland.managesystem.R;
import com.isunland.managesystem.entity.PlanManageProgress;
import java.util.List;

/**
 * 对象功能:
 * 开发公司: 北京信普达系统工程有限公司
 * 开发人员: HuXiaoDan
 * 创建时间: 2017/4/25 13:38
 */
public class PlanManageProgressListAdapter extends ArrayAdapter<PlanManageProgress> {

  /**
   * ViewHolder class for layout.<br />
   * <br />
   * Auto-created on 2015-09-21 13:36:53 by Android Layout Finder
   * (http://www.buzzingandroid.com/tools/android-layout-finder)
   */
  private static class ViewHolder {
    public final LinearLayout rootView;
    public final TextView tvPlanCompleteWorkProcess;
    public final TextView tvPlanFinishPercentWorkProcess;
    public final TextView tvPlanRegeditTimeWorkProcess;

    private ViewHolder(LinearLayout rootView, TextView tvPlanCompleteWorkProcess,
        TextView tvPlanFinishPercentWorkProcess, TextView tvPlanRegeditTimeWorkProcess) {
      this.rootView = rootView;
      this.tvPlanCompleteWorkProcess = tvPlanCompleteWorkProcess;
      this.tvPlanFinishPercentWorkProcess = tvPlanFinishPercentWorkProcess;
      this.tvPlanRegeditTimeWorkProcess = tvPlanRegeditTimeWorkProcess;
    }

    public static ViewHolder create(LinearLayout rootView) {
      TextView tvPlanStatusWorkProcess =
          (TextView) rootView.findViewById(R.id.tv_planComplete_workProcess);
      TextView tvPlanFinishPercentWorkProcess =
          (TextView) rootView.findViewById(R.id.tv_planFinishPercent_workProcess);
      TextView tvPlanRegeditTimeWorkProcess =
          (TextView) rootView.findViewById(R.id.tv_planRegeditTime_workProcess);
      return new ViewHolder(rootView, tvPlanStatusWorkProcess, tvPlanFinishPercentWorkProcess,
          tvPlanRegeditTimeWorkProcess);
    }
  }

  @Override public View getView(int position, View convertView, ViewGroup parent) {
    final ViewHolder vh;
    if (convertView == null) {
      View view = mInflater.inflate(R.layout.adapter_plan_detail_list, parent, false);
      vh = ViewHolder.create((LinearLayout) view);
      view.setTag(vh);
    } else {
      vh = (ViewHolder) convertView.getTag();
    }

    PlanManageProgress item = getItem(position);
    vh.rootView.setBackgroundColor(Color.WHITE);
    vh.tvPlanCompleteWorkProcess.setText(item.getExcDesc());
    vh.tvPlanFinishPercentWorkProcess.setText(
        String.format("%s%%", item.getComprate() != null ? item.getComprate() : 0));
    if (!TextUtils.isEmpty(item.getStaffname())) {
      vh.tvPlanRegeditTimeWorkProcess.setVisibility(View.VISIBLE);
      vh.tvPlanRegeditTimeWorkProcess.setText("　　＠" + item.getStaffname());
    } else {
      vh.tvPlanRegeditTimeWorkProcess.setVisibility(View.GONE);
    }

    return vh.rootView;
  }

  private LayoutInflater mInflater;

  // Constructors
  public PlanManageProgressListAdapter(Context context, List<PlanManageProgress> objects) {
    super(context, 0, objects);
    this.mInflater = LayoutInflater.from(context);
  }
}

